﻿using System;
using System.Drawing;
using SalesAndStoreApp.BLL;
using SalesAndStoreApp.DAL.DAO;

namespace SalesAndStoreApp.UI.StoreManager
{
    public partial class ProductSetupUI : System.Web.UI.Page
    {
        private ProductManager productManager = new ProductManager();

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cache.SetNoStore();
            messageLabel.Text = "";
        }

        protected void saveButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (nameTextBox.Text!=""&&sellUnitPriceText.Text!=""&&buyUnitPriceText.Text!=""&& reOrderLevelTextBox.Text!=""&&initialQtyTextBox.Text!="")
                {
                    Product product = new Product();
                    product.Name = nameTextBox.Text;
                    product.SaleUnitPrice = double.Parse(sellUnitPriceText.Text);
                    product.BuyUnitPrice = double.Parse(buyUnitPriceText.Text);
                    Inventory inventory = new Inventory();
                    inventory.Quantity = int.Parse(initialQtyTextBox.Text);
                    inventory.ReOrderLevel = int.Parse(reOrderLevelTextBox.Text);
                    product.Inventory = inventory;
                    messageLabel.ForeColor = Color.Green;
                    messageLabel.Text = productManager.SaveProductSetup(product);
                    ClearTextBoxes();
                }
                else
                {
                    throw new Exception("Please provide all field information properly, no field should be blank");
                }
            }
            catch (Exception exception)
            {
                messageLabel.ForeColor = Color.Red;
                messageLabel.Text = exception.Message;
            }
            
        }

        private void ClearTextBoxes()
        {
            throw new NotImplementedException();
        }
    }
}